import addDetailCard from "./add-detail-card";
import addNoDetailCard from "./add-nodetail-card";
import addFieldCard from "./add-field-card";
import addFieldReport from "./add-field-report";
import cubeCardClear from "./cube-card-clear";
import editReportField from "./edit-report-field";
import setBackColor from "./set-back-color";
import setBold from "./set-bold";
import setBorder from "./set-border";
import setCellSpan from "./set-cell-span";
import setFontFamily from "./set-font-family";
import setFontSize from "./set-font-size";
import setFontType from "./set-font-type";
import setForeColor from "./set-fore-color";
import setHAlign from "./set-h-align";
import setItalic from "./set-italic";
import setUnderline from "./set-underline";
import setVAlign from "./set-v-align";
import setWordwrap from "./set-wordwrap";
import edcExcelTableInsertCol from "./edc-excel-tableInsertCol";
import edcExcelTableInsertRow from "./edc-excel-tableInsertRow";
import edcExcelTableDeleteRow from "./edc-excel-tableDeleteRow";
import edcExcelTableDeleteCol from "./edc-excel-tableDeleteCol";
import changeCellType from "./change-cell-type";
import autoSignField from "./auto-sign-field";
import deleteDetailCard from "./delete-detail-card";
import clearContent from "./clear-content";
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;


export const getRange = (sheet, row, col) => {
    const span = sheet.getSpan(row, col);
    if (span) {
        return sheet.getRange(span.row, span.col, span.rowCount, span.colCount);
    } else {
        return sheet.getCell(row, col);
    }
}

export const register = (commandManager) => {
    commandManager.register('setFontFamily', setFontFamily);
    commandManager.register('setFontSize', setFontSize);
    commandManager.register('setBold', setBold);
    commandManager.register('setItalic', setItalic);
    commandManager.register('setUnderline', setUnderline);
    commandManager.register('setHAlign', setHAlign);
    commandManager.register('setVAlign', setVAlign);
    commandManager.register('setBorder', setBorder);
    commandManager.register('setBackColor', setBackColor);
    commandManager.register('setForeColor', setForeColor);
    commandManager.register('addFieldCard', addFieldCard);
    commandManager.register('setCellSpan', setCellSpan);
    commandManager.register('addDetailCard', addDetailCard);
    commandManager.register('addNoDetailCard', addNoDetailCard)
    commandManager.register('setFontType', setFontType);
    commandManager.register('cubeCardClear', cubeCardClear);
    commandManager.register('editReportField', editReportField);
    commandManager.register('addFieldReport', addFieldReport);
    commandManager.register('setWordwrap', setWordwrap);
    commandManager.register('edc.excel.tableInsertCol', edcExcelTableInsertCol);
    commandManager.register('edc.excel.tableInsertRow', edcExcelTableInsertRow);
    commandManager.register('edc.excel.tableDeleteRow', edcExcelTableDeleteRow);
    commandManager.register('edc.excel.tableDeleteCol', edcExcelTableDeleteCol);

    commandManager.register('changeCellType', changeCellType);
    commandManager.register('autoSignField', autoSignField);
    commandManager.register('deleteDetailCard', deleteDetailCard);
    commandManager.register('clearContent', clearContent);
}
export const menuData = store => [{
    name: "edc.excel.insert",
    text: getLabel('502984', '插入'),
    workArea: "viewport",
    subMenu: [{
        command: "gc.spread.contextMenu.insertRows",
        text: `<div style='width:180px;'>
                     ${getLabel('502985', '插入行')}
                </div>`,
        name: "edc.excel.insertLine",
        workArea: "viewport"
    }, {
        command: "gc.spread.contextMenu.insertColumns",
        text: `<div style='width:180px;'>
                    ${getLabel('502986', '插入列')}
                </div>`,
        name: "edc.excel.insertRow",
        workArea: "viewport"
    }]
}, {
    name: "edc.excel.tableInsert",
    text: getLabel('502984', '插入'),
    workArea: "viewporttable",
    subMenu: [{
        command: store['edc.excel.tableInsertLeftCol'],
        text: getLabel('502987', '在左侧插入表列'),
        name: "edc.excel.tableInsertLeftCol",
        workArea: "viewporttable",
    }, {
        command: store['edc.excel.tableInsertRightCol'],
        text: getLabel('502988', '在右侧插入表列'),
        name: "edc.excel.tableInsertRightCol",
        workArea: "viewporttable",
    }, {
        command: store['edc.excel.tableInsertTopRow'],
        text: getLabel('502989', '在上方插入表行'),
        name: "edc.excel.tableInsertTopRow",
        workArea: "viewporttablenofirstdatarow",
    }, {
        command: store['edc.excel.tableInsertBottomRow'],
        text: getLabel('502990', '在下方插入表行'),
        name: "edc.excel.tableInsertBottomRow",
        workArea: "viewporttable",
    }]
}, {
    name: "edc.excel.tableDelete",
    text: getLabel(502286, '删除'),
    workArea: "viewporttable",
    subMenu: [{
        command: store['edc.excel.tableDeleteCol'],
        text: getLabel('502991', '删除表列'),
        name: "edc.excel.tableDeleteCol",
        workArea: "viewporttable",
    }, {
        command: store['edc.excel.tableDeleteRow'],
        text: getLabel('502992', '删除表行'),
        name: "edc.excel.tableDeleteRow",
        workArea: "viewporttablenofirstdatarow",
    }]
}]
export const setRightMenu = (store, isTable, isFirstDataRow) => {
    const datas = menuData(store);
    if (isTable) {
        if (isFirstDataRow) {

            store.workbook.contextMenu.menuData = datas.filter(d => {
                if (d.subMenu) {
                    d.subMenu = d.subMenu.filter(f => {
                        return /table/i.test(f.workArea) && !(/nofirstdatarow/i.test(f.workArea))
                    });
                }
                return /table/i.test(d.workArea) && !(/nofirstdatarow/i.test(d.workArea))
            });
        } else {
            store.workbook.contextMenu.menuData = datas.filter(d => /table/i.test(d.workArea))
        }
    } else {
        store.workbook.contextMenu.menuData = datas.filter(d => d.workArea !== 'viewporttable');
    }
}